package com.sztx.worker_monitor.web.handle;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sztx.worker_monitor.dataaccess.dao.mysql.SchedNameDAO;
import com.sztx.worker_monitor.dataaccess.domain.SchedNameDO;

@Component
public class SchedNameHandle {
	@Autowired(required = false)
	private SchedNameDAO schedNameDAO;

	public List<String> getSchedNameList(){
		
		List<SchedNameDO> schedNameDOs = schedNameDAO.getAllSchedName();
		List<String> schedNames = new ArrayList<String>();
		for(SchedNameDO schedNameDO:schedNameDOs){
			String schedName = schedNameDO.getName();
			schedNames.add(schedName);
		}
		return schedNames;	
	}
	
	public String  delSchedName(String schedName){
		if(schedName == null || "".equals(schedName)) return "输入名称错误，无法删除";
		
		SchedNameDO schedNameDO = schedNameDAO.findItemBySchedName(schedName);
		if(schedNameDO == null){
			return "该名称不存在";
		} 
		else{
			schedNameDAO.deleteSchedName(schedName);
		}
		return null;
	}
	
	public String  addSchedName(String schedName){
		
if(schedName == null || "".equals(schedName)) return "输入名称错误，无法添加";
		
		SchedNameDO schedNameDO = schedNameDAO.findItemBySchedName(schedName);
		if(schedNameDO == null){
			schedNameDAO.insertSchedName(schedName);
		} 
		else if(schedNameDO.getStatus() == 1){
				schedNameDAO.reAddSchedName(schedName);
		}
		else{
			return "该名称已经存在";
		}
		return null;	
		
	} 

}
